<?php
use app\admin\model\SystemMenu;
use think\facade\Db;
use think\migration\Seeder;


class SystemMenuSupply extends Seeder
{
    public function run()
    {
		// 启动事务
        Db::startTrans();
        try {
			$menuData = $this->getmenuData();
			$this->createMenu($menuData);
		    Db::commit();
        } catch (\Throwable $th) {
            Db::rollback();
        }
    }

    /**
     * 递归创建菜单数据
     * @MethodAuthor: 聂哥
     * @Date: 2023-03-31 14:47:46
     */
    protected function createMenu($menuData,$pid = 0)
    {
		foreach( $menuData as $item ){
			$item['pid'] = $pid;
			$menu = SystemMenu::create($item);
			$id = $menu->id;
			if( isset($item['child']) && !empty($item['child']) ){
				$this->createMenu($item['child'],$id);
			}
		}
    }

    /**
     * 菜单列表数据
     * @MethodAuthor: 聂哥
     * @Date: 2023-03-31 14:47:46
     */
    protected function getmenuData()
    {
        $arr = [
            [
                'title' => '供求小程序',
                'icon' => 'fa fa-list',
                'child' => [
                    [
                        'title' => '横幅广告',
                        'icon' => 'fa fa-bullhorn',
                        'href' => 'supply.banner/index',
                        'target' => '_parent'
                    ],
                    [
                        'title' => '合作车辆',
                        'icon' => 'fa fa-list',
                        'child' => [
                            [
                                'title' => '车辆列表',
                                'icon' => 'fa fa-car',
                                'href' => 'supply.truck/index'
                            ],
                            [
                                'title' => '车辆添加',
                                'icon' => 'fa fa-arrow-circle-right',
                                'href' => 'supply.truck/add'
                            ],
                        ]
                    ],
                    [
                        'title' => '申请订单',
                        'icon' => 'fa fa-credit-card',
                        'child' => [
                            [
                                'title' => '求购列表',
                                'icon' => 'fa fa-align-left',
                                'href' => 'supply.order/index'
                            ],
                            [
                                'title' => '供应列表',
                                'icon' => 'fa fa-align-right',
                                'href' => 'supply.order/index2'
                            ],
                        ]
                    ],
                    [
                        'title' => '报价管理',
                        'icon' => 'fa fa-money',
                        'href' => 'supply.quoted/index',
                        'target' => '_parent'
                    ],
                    [
                        'title' => '化工资讯',
                        'icon' => 'fa fa-list',
                        'child' => [
                            [
                                'title' => '资讯列表',
                                'icon' => 'fa fa-newspaper-o',
                                'href' => 'supply.news/index'
                            ],
                            [
                                'title' => '资讯添加',
                                'icon' => 'fa fa-edit',
                                'href' => 'supply.news/add'
                            ],
                        ]
                    ],
                    [
                        'title' => '产品管理',
                        'icon' => 'fa fa-product-hunt',
                        'child' => [
                            [
                                'title' => '产品分类',
                                'icon' => 'fa fa-certificate',
                                'href' => 'supply.catrgory/index'
                            ],
                            [
                                'title' => '产品列表',
                                'icon' => 'fa fa-list-ul',
                                'href' => 'supply.product/index'
                            ]
                        ]
                    ],
                    [
                        'title' => '合作企业',
                        'icon' => 'fa fa-building',
                        'href' => 'supply.corporate/index',
                        'target' => '_parent'
                    ]
                    
                ]
            ]
        ];
        return $arr;
    }
}